import java.util.*;

public class Main {
    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(Arrays.toString(s.twoSum(new int[]{2,7,11,15}, 9)));
        System.out.println(Arrays.toString(s.twoSum(new int[]{3,2,4}, 6)));
        System.out.println(Arrays.toString(s.twoSum(new int[]{3,3}, 6)));
    }
}


class Solution {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> value2idx = new HashMap<>();
        for (int i = 0; i < nums.length; i++){
            if(value2idx.containsKey(target - nums[i])){
                return new int[]{value2idx.get(target - nums[i]), i};
            }
            value2idx.put(nums[i], i);
        }
        return null;
    }
}